#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int dx[4] = { 1, -1, 0, 0 };
    int dy[4] = { 0, 0, 1, -1 };
    bool bp[51][51];
    int b;
    vector<vector<int>> floodFill(vector<vector<int>>& image, int sr, int sc, int color) {
        b = image[sr][sc];
        image[sr][sc] = color;
        dfs(image, sr, sc, color);
        return image;
    }
    void dfs(vector<vector<int>>& image, int sr, int sc, int color)
    {
        for (int k = 0; k < 4; k++)
        {
            int x = sr + dx[k], y = sc + dy[k];
            if (x >= 0 && x < image.size() && y >= 0 && y < image[x].size() && image[x][y] == b && bp[x][y] == false)
            {
                bp[x][y] = true;
                image[x][y] = color;
                dfs(image, x, y, color);
            }
        }
    }
};